package com.amigo.online.provider.manager.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.amigo.online.common.base.controller.BaseController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.provider.manager.model.entity.MusicTbl;
import com.amigo.online.provider.manager.service.MusicTblService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@RestController
@RequestMapping(value = "/music", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class MusicTblController extends BaseController {

    @Resource
    private MusicTblService musicTblService;

    /**
     * 查询音频
     *
     * @param musicTbl
     * @return
     */
    @PostMapping(value = "/getMusicTbl")
    public ResponseEntity<Response> getMusicTbl(@RequestBody MusicTbl musicTbl) {
        JSONObject result = new JSONObject();
        // 分页语句
        Page<Object> page = PageHelper.startPage(musicTbl.getPageNo(), 10);
        List<MusicTbl> musiclist = musicTblService.findMusicList(musicTbl);
        result.put("musiclist", musiclist);
        result.put("pagetotal", page.getTotal());
        return success(result);
    }

    /**
     * 添加音频
     *
     * @param musicTbl
     * @return
     */
    @PostMapping(value = "/saveMusicTbl")
    public ResponseEntity<Response> saveMusic(@RequestBody MusicTbl musicTbl) {
        return success(musicTblService.saveMusic(musicTbl));
    }

    /**
     * 刪除音频
     *
     * @param musicTbl
     * @return
     */
    @PutMapping(value = "/deleteMusicTbl")
    public ResponseEntity<Response> deleteMusic(@RequestBody MusicTbl musicTbl) {
        return success(musicTblService.deleteMusic(musicTbl));
    }

    /**
     * 修改音乐表
     *
     * @param musicTbl
     * @return
     */
    @PutMapping(value = "/updateMusic")
    public ResponseEntity<Response> updateMusic(@RequestBody MusicTbl musicTbl) {
        return success(musicTblService.updateMusic(musicTbl));
    }

}
